package com.example.controller;

import com.example.common.Result;
import com.example.entity.Evaluate;
import com.example.service.EvaluateService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 评价(Evaluate)表控制层
 */
@RestController
public class EvaluateController {
    
    @Resource
    private EvaluateService evaluateService;

    // 信息列表
    @ResponseBody
    @RequestMapping("evaluateList")
    public Result evaluateList(@RequestParam(defaultValue = "1", value = "pageNum") Integer pageNum,
                              @RequestParam(defaultValue = "1", value = "pageSize") Integer pageSize,
                              HttpServletRequest request) {
        String key = request.getParameter("key");
        String goodsid = request.getParameter("goodsid");
        
        PageInfo<Evaluate> pageInfo = evaluateService.getEvaluateList(pageNum, pageSize, key, goodsid);
        return Result.success(pageInfo);
    }
    
    // 添加评价信息
    @ResponseBody
    @RequestMapping("evaluateAdd")
    public Result evaluateAdd(Evaluate evaluate, HttpServletRequest request) {
        evaluateService.addEvaluate(evaluate);
        return Result.success();
    }

    // 回复评价信息
    @ResponseBody
    @RequestMapping("evaluateEdit")
    public Result evaluateEdit(Evaluate evaluate, HttpServletRequest request) {
        evaluateService.replyEvaluate(evaluate);
        return Result.success();
    }

    // 删除信息
    @ResponseBody
    @RequestMapping("evaluateDel")
    public Result evaluateDel(int id, HttpServletRequest request) {
        evaluateService.deleteEvaluate(id);
        return Result.success();
    }
    
    // 批量删除信息
    @ResponseBody
    @RequestMapping("evaluateDeleteAll")
    public Result typeDeleteAll(HttpServletRequest request) {
        String vals = request.getParameter("vals");
        evaluateService.batchDeleteEvaluate(vals);
        return Result.success();
    }
}

